﻿using MediatR;
using Rabbit.Domain;
using Rabbit.ErCode;
using Rabbit.lnfarnum;
using Rabbit.Write.API.WriteRepository.Commder;

namespace Rabbit.Write.API.WriteRepository.CommdHnader
{
    /// <summary>
    ///删除方法
    /// </summary>
    public class DeleteMerchanCommdHdner : IRequestHandler<DeleteMerchanCommder, APIResult<object>>
    {

        private readonly IBaseRepository<MerchandiseMangem> baseRepository;

        public DeleteMerchanCommdHdner(IBaseRepository<MerchandiseMangem> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<object>> Handle(DeleteMerchanCommder request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();

            result.Code = ReCode.删除成功;
            result.Mage =ReCode.删除成功.ToString();


            var list = baseRepository.GetAll().Where(X => X.MerchanMid == request.MerchandMangeid).FirstOrDefault();

            if (list ==null)
            {
                result.Code = ReCode.删除失败;
                result.Mage = ReCode.删除失败.ToString();
            }

            list.Idate = true;
            baseRepository.Update(list);
            return Task.FromResult(result);
            
        }
    }
}
